package com.zhixun.mobile.sys.utils;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.boxin.ims.modules.wechat.entity.WechatMember;

public class SessionMemberUtils {
	
	private static Map<String,Object> sessionMap ;
	static {
		sessionMap = new HashMap<String,Object> ();
		
	}
	
	/**
	 * @author Jakemanse
	 * @time 2014-3-3  下午3:37:41
	 * @function <p> 获取已登录的会员  </p>
	 * @param userId	厂家ID
	 * @return
	 */
	public static WechatMember getSessionMemberByUserId(HttpServletRequest  request, String userId){
		return   (WechatMember) request.getSession().getAttribute("member_"+userId);
		//return  (WechatMember) sessionMap.get("member_"+userId);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2014-3-1  ����10:08:28
	 * @function <p> ��ȡ��¼��Ա�� name  </p>
	 * @param userId   Ϊ�ͻ���userID,�ǻ�Ա��ID
	 * @return
	 */
	public static Map<String,Object> getSessionMemberName(HttpServletRequest  request,String userId){
		return (Map<String,Object>)request.getSession().getAttribute("username_"+userId);
//		return (Map<String,Object>)sessionMap.get("username_"+userId);
	}
	
	

	
	
	/**
	 * @author Jakemanse
	 * @time 2014-3-1  ����10:06:29
	 * @function <p> ���Session���� </p>
	 * @param key
	 * @param value
	 */
	public static void addSessionValue(HttpServletRequest  request,	String key,Object value){
		request.getSession().setAttribute(key, value);
		
		//sessionMap.put(key, value);
	}
	
	
	
	public static void removeSession(HttpServletRequest  request,	 String key,Object value){
		request.getSession().removeAttribute(key);
		//sessionMap.remove(key);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2014-3-1  ����10:12:42
	 * @function <p> �жϻ�Ա�Ƿ��Ѿ���¼ </p>
	 * @param userId
	 * @return
	 */
	public static boolean isLogined(HttpServletRequest  request,String userId){
		Map<String,Object>  smap = getSessionMemberName(request,userId) ;
		return !(smap==null || smap.isEmpty());
	}
	/**
	 * @author songyan
	 * @time 2014-3-1  ����10:03:48
	 * @function <p> ��ȡsession </p>
	 * @param sessionKey
	 * @return
	 */
	public static String getSessionByName(HttpServletRequest  request,String sessionKey){
		return (String)request.getSession().getAttribute(sessionKey);
		
		
	}
	
}
